<?php
/**
 * 2021/3/9
 * Created by breeze
 * User: breeze
 */

namespace app\common\model;


use think\Model;

class Admin extends Model
{
    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getAdminAll(){
        $result = $this->order('id','desc')
            ->select()->toArray();
        return $result;
    }

    public function getAdminUserByName($AdminName){
        $where = [
            "name" => $AdminName
        ];

        $result = $this->where($where)->find();
        return $result;
    }

    /**
     * @param $id
     * @param $data
     * @return bool
     */
    public function updateById($id,$data){
        $id = intval($id);
        $res = $this->where(
            [
                "id" => $id
            ]
        )->find()->save($data);
        return $res;
    }
    public function getList(){
        $res = $this->select();
        return $res;
    }
    public function getDetailById($id){
        $res = $this->find($id);
        return $res;
    }

    public function changeFieldById($where,$data){
        $res = $this->where($where)->find()->save($data);
//        dump($res);exit();
        return $res;
    }
    public function add($data){
        $res = $this->save($data);
        return $res;
    }
    public function removeByWhere($where){
        $result = $this->where($where)->delete();
        return $result;
    }
}